import urllib
from xml.etree.ElementTree import *

IDICT = "http://dict-co.iciba.com/api/dictionary.php?w="

def query_word_from_icba(word):
    sock = urllib.urlopen(IDICT + word)
    content = sock.read()
    sock.close()
    return content


def parse_icba_item(xml_str):
    word = XML(xml_str)
    print "key ", word.find("key").text
    print "ps:", word.find("ps").text
    print "pron: ", word.find("pron").text
    print "pos: ", word.find("pos").text
    print "acceptation", word.find("acceptation").text


if __name__ == "__main__":
    parse_icba_item(query_word_from_icba("hello"))
